<template>
  <div>

    <!-- 一条文章单元格 -->
    <van-cell
    border
    @click="$router.push('/article?art_id='+item.art_id)">
  <!-- 反馈面板 -->
    <van-action-sheet
      v-model="show"
      :actions="actions"
      @select="onSelect"
      get-container="body"
      cancel-text="取消"
    />
    <!-- 二级面板 -->
    <van-action-sheet
      v-model="show2"
      :actions="actions2"
      @select="onSelect"
      get-container="body"
      cancel-text="取消"
    />
    <van-dialog
      v-model="show3"
      title="反馈其他问题"
      show-cancel-button
      get-container="body"
      @confirm="onconfirmFn"
    >
      <van-field
      v-model.trim="msg"
      type="textarea"
      placeholder="请输入反馈的内容1-100字"
      border
      v-jujiao
    />

    </van-dialog>
    <van-cell>

    <!-- 标题区域的插槽 -->
    <template #title>
      <div class="title-box">
        <!-- 标题 -->
        <span>{{ item.title }}</span>
        <img
        class="thumb"
        :src="item.cover.images[0]"
        v-if="item.cover.type ===1"
         />
      </div>
      <div class="thumb-box" v-if="item.cover.type >1">
        <img class="thumb" v-for="(imgurl,index) in item.cover.images" :src="imgurl"
        :key="index"
        />

      </div>

    </template>
    <!-- label 区域的插槽 -->
    <template #label>
      <div class="label-box">
        <div>
          <span>{{ item.aut_name }}</span>
          <span>{{ item.comm_count }}评论</span>
          <!-- 处理时间 -->
          <span>{{fromatTimeAgoFn(item.pubdate) }}</span>
        </div>
        <!-- 反馈按钮 -->
        <van-icon
        name="cross"
        v-if="isShowCross"
        @click.stop="oncloseClick"/>
      </div>
    </template>
    </van-cell>
  </van-cell>
  </div>

</template>

<script>
import { firstActions, secondActions } from '@/api/report'
import { articleDislikeAPI, articleReportsAPI } from '@/api/home'
import { fromatTimeAgoFn } from '@/utils/date'
import { Toast } from 'vant'
export default {
  name: 'ArticleItem',
  props: {
    item: {
      type: Object,
      required: true
    },
    i: Number,
    isShowCross: {
      type: Boolean,
      default: true
    }
  },
  data () {
    return {
      msg: '',
      show: false, // 初始化为隐藏状态
      show2: false, // 初始化为隐藏状态
      show3: false, // 初始化为隐藏状态
      actions: firstActions, // 将那边数据直接调用
      actions2: secondActions
      // secondActions
    }
  },
  methods: {
    async onconfirmFn () {
      if (this.msg.length === 0) {
        Toast('内容不能为空')
      } else {
        await articleReportsAPI({
          artId: this.item.art_id,
          type: '0',
          remark: this.msg
        })
        Toast('反馈成功')
      }
    },
    async onSelect (action) {
      if (action.id === 22) {
        this.actions = this.actions2
      } else if (action.id === 11) {
        // 删除点击不感兴趣的文章，让他的父级的父级帮忙删除
        this.$emit('del-art', this.i)
        this.show = false
        await articleDislikeAPI({
          artId: this.item.art_id
        })
      } else if (action.id === 33) { // 拉黑作者

      } else { // 如果不是上面那些，就是二级的
        if (action.id === 0) {
          this.show3 = true
          this.show2 = this.show = false
        }
        await articleReportsAPI({
          artId: this.item.art_id,
          type: action.id + '',
          remark: '用户输入的原因' || action.name
        })
        // Notify({ type: 'success', message: '举报成功' })

        // Notify({ type: 'warning', message: '举报失败' })
      }
    },
    // 点击X号时，让隐藏的数据显示出来
    oncloseClick () {
      this.show = true
    },
    // 导入时间转换的封装好的
    fromatTimeAgoFn: fromatTimeAgoFn
  }
}
</script>

<style scoped lang="less">
/* 标题样式 浏览器渲染文档*/
.title-box {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

/* label描述样式 */
.label-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* 文章信息span */
.label-box span {
  margin: 0 3px;
  &:first-child {
    margin-left: 0;
  }
}
/* 图片的样式, 矩形黄金比例：0.618 */
.thumb {
  width: 113px;
  height: 70px;
  background-color: #f8f8f8;
  object-fit: cover;
}

/* 三图, 图片容器 */
.thumb-box {
  display: flex;
  justify-content: space-between;
}
</style>
